﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ninject.Core;
using Ninject.Core.Parameters;
using Ninject.Core.Behavior;
using Milkify.Interfaces;

namespace Milkify
{
    internal static class KernelContainer
    {
        private static IKernel sKernel;
        public static IKernel Kernel
        {
            get { return sKernel; }
            set
            {
                if (sKernel != null)
                    throw new InvalidOperationException("A kernel has already been registered.");
                sKernel = value;
            }
        }

        public static void Initialize()
        {
            KernelOptions options = new KernelOptions()
            {
                DefaultBehaviorType = typeof(TransientBehavior)
            };
            IKernel kernel = new StandardKernel(options,
                new MilkifyInfrastructureModule(),
                new MilkifyControllersModule(),
                new MilkifyViewsModule());
            Initialize(kernel);
        }

        public static void Initialize(IKernel kernel)
        {
            KernelContainer.Kernel = kernel;
        }

        public static void Shutdown()
        {
            KernelContainer.Kernel.Dispose();
        }
    }
}
